//
//  MYGMedicalToolsTIMIController.swift
//  MYDoctor
//
//  Created by 林矗 on 2024/5/27.
//

import UIKit
import JXSegmentedView

class MYGMedicalToolsTIMIController: MYGBaseController {

    var selectedIndex = 0

    override func viewDidLoad() {
        super.viewDidLoad()

        view.addSubview(segmentView)
        view.addSubview(containView)
        segmentView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(0)
            make.height.equalTo(48)
        }
        containView.snp.makeConstraints { make in
            make.left.right.bottom.equalToSuperview()
            make.top.equalTo(segmentView.snp.bottom)
        }
        
        // Do any additional setup after loading the view.
    }
    
    
    private lazy var segmentView: JXSegmentedView = {
        let segment = JXSegmentedView()
        segment.delegate = self
        segment.dataSource = dataSource
        segment.defaultSelectedIndex = self.selectedIndex
        segment.backgroundColor = .white
        segment.listContainer = containView
        let indicator = JXSegmentedIndicatorLineView()
        indicator.indicatorColor = .rgba(32, 92, 255, 1)
        indicator.indicatorHeight = 2
        indicator.indicatorWidth = 44
        indicator.indicatorPosition = .bottom
        indicator.verticalOffset = 4
        segment.indicators = [indicator]
        return segment
    }()
    
    private lazy var dataSource: JXSegmentedTitleDataSource = {
        let dataSource = JXSegmentedTitleDataSource()
        dataSource.titles = ["UA/NSTEMI患者", "STEMI患者"]
        dataSource.titleNormalFont = .regular(13)
        dataSource.titleNormalColor = .rgba(118, 118, 118, 1)
        dataSource.titleSelectedFont = .regular(16)
        dataSource.titleSelectedColor = .rgba(32, 92, 255, 1)
        return dataSource
    }()
    
    private lazy var containView: JXSegmentedListContainerView = {
        let view = JXSegmentedListContainerView(dataSource: self)
        return view
    }()
    
    private lazy var UAView: MYGMedicalToolsTIMIUAView = {
        let view = MYGMedicalToolsTIMIUAView()
        return view
    }()
    
    private lazy var STEMIView: MYGMedicalToolsTIMISTEMIView = {
        let view = MYGMedicalToolsTIMISTEMIView()
        return view
    }()
}

extension MYGMedicalToolsTIMIController: JXSegmentedViewDelegate {
    func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {
        
    }
}

extension MYGMedicalToolsTIMIController: JXSegmentedListContainerViewDataSource {
    func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
        2
    }
    
    func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> any JXSegmentedListContainerViewListDelegate {
        return [UAView, STEMIView][index]
    }
}
